import pandas as pd
import matplotlib.pyplot as plt
#解决中文无法正确显示的问题
plt.rcParams['font.sans-serif']='SimHei'
plt.rcParams['axes.unicode_minus']=False
def main():
    # 读CSV文件，将数据加载到程序中中
    data = pd.read_csv('testfile.csv')
    #进行分片，取前五行数据
    data = data.iloc[0:5, :]
    print(data)
    #将属性中object类型转化为可执行的float和int类型
    data['H-index Citations']=data['H-index Citations'].astype(float)
    data['Citations per Paper']=data['Citations per Paper'].astype(float)
    data['Academic Reputation']=data['Academic Reputation'].astype(float)
    data['Employer Reputation']=data['Employer Reputation'].astype(float)
    data['rank'] = data['rank'].astype(int)
    data['overall'] = data['overall'].astype(float)
    #data.plot(kind='bar', x='rank',
        #      y=['H-index Citations', 'Citations per Paper', 'Academic Reputation', 'Employer Reputation'],
             # title='各所大学H-index Citations', color=["red", "blue", "pink", "yellow"], xlim=(0, 120), ylim=(40, 100))
    #ax0=data.plot(kind='bar', x='university',
            #  y=['H-index Citations', 'Citations per Paper', 'Academic Reputation', 'Employer Reputation'],
           #   title='各所大学H-index Citations', color=["red", "blue", "pink", "yellow"], ylim=(40, 100))
   # ax0.tick_params(axis='x',labelsize=5)
    # 可视化效果显示筛选前五名学校各属性的结果，折线图
    ax1=data.plot(kind='line',x='university',y='H-index Citations',title='各所大学H-index Citations(H指数引用文献)',color="red",ylim=(70,100))
    ax1.tick_params(axis='x', labelsize=5)
    for a, b in zip(data['rank']-1, data['H-index Citations']):
        ax1.text(a, b + 0.002, '%.f' % b, ha='center', fontsize=9)
    ax2=data.plot(kind='line',x='university',y='Citations per Paper',title='各所大学Citations per Paper(每篇论文引用次数)',color="blue",ylim=(40,100))
    ax2.tick_params(axis='x', labelsize=5)
    for a, b in zip(data['rank'] - 1, data['Citations per Paper']):
        ax2.text(a, b + 0.002, '%.f' % b, ha='center', fontsize=9)
    ax3=data.plot(kind='line',x='university',y='Academic Reputation',title='各所大学Academic Reputation(学术声誉)',color="yellow",ylim=(40,100))
    ax3.tick_params(axis='x', labelsize=5)
    for a, b in zip(data['rank'] - 1, data['Academic Reputation']):
        ax3.text(a, b + 0.002, '%.f' % b, ha='center', fontsize=9)
    ax4=data.plot(kind='line',x='university',y='Employer Reputation',title='各所大学Employer Reputation(雇主满意度)',color="black",ylim=(40,100))
    ax4.tick_params(axis='x', labelsize=5)
    for a, b in zip(data['rank'] - 1, data['Employer Reputation']):
        ax4.text(a, b + 0.002, '%.f' % b, ha='center', fontsize=9)
    ax5 = data.plot(kind='line', x='university', y='overall', title='各所大学Overall(整体)',
                    color="blue", ylim=(40, 100))
    ax5.tick_params(axis='x', labelsize=5)
    for a, b in zip(data['rank'] - 1, data['overall']):
        ax5.text(a, b + 0.002, '%.f' % b, ha='center', fontsize=9)
    plt.show()
if __name__ == '__main__':
    main()